package com.shf.lease.web.admin.controller.apartment;

import com.shf.lease.entity.LeaseTerm;
import com.shf.lease.result.Result;
import com.shf.lease.web.admin.controller.apartment.request.TermDelCmd;
import com.shf.lease.web.admin.service.LeaseTermService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 叶枫
 * @date 2024/7/4.
 */

@RestController
@RequestMapping("/admin/term")
@Tag(name = "租期管理")
public class LeaseTermController {
    @Resource
    private LeaseTermService leaseTermService;

    @Operation(summary = "查询租期列表")
    @GetMapping("/list")
    public Result<List<LeaseTerm>> getLeaseTermList() {
        return Result.ok(leaseTermService.list());
    }
    @Operation(summary = "新增or更新租期")
    @RequestMapping(value = "/saveOrUpdate",method = {RequestMethod.POST,RequestMethod.PUT})
    public Result<?> saveOrUpdateLeaseTerm(LeaseTerm leaseTerm) {
        return leaseTermService.saveOrUpdate(leaseTerm) ? Result.ok() : Result.fail();
    }
    @Operation(summary = "删除租期")
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    public Result<?> deleteLeaseTerm(@RequestBody @Valid TermDelCmd request) {
        return leaseTermService.removeById(request.getId()) ? Result.ok() : Result.fail();
    }
}
